/*
 * Logger.cpp
 *
 *  Created on: Jun 3, 2011
 *      Author: madboyka
 */

#include "Logger.h"
#include <time.h>
#include <stdio.h>
QString Logger::filename;
bool Logger::initialized = false;

void Logger::init(QString fname)
{
	if (initialized)
	{
		printf("Logger already initialized!");
		return;
	}
	initialized = true;
	filename = fname;
}

void Logger::debug(QString format, ...)
{
	va_list argptr;
	va_start(argptr,format);
	log(DebugLog, format, argptr);
	va_end(argptr);
}

void Logger::log(LogLevel logLevel, const char *format, va_list vararg)
{
	if (!initialized)
	{
		printf("Logger not initialized!");
		return;
	}
	time_t timestamp = time(NULL);
	char stime[11];
	strftime(stime, 11, "[%H:%M:%S]", localtime(&timestamp));
	printf("%s ",stime);
	//		int len = strlen(message);
	//		char buffer[(len + 8 + 5)];
	vprintf(format,vararg);
	puts("");
}
void Logger::log(LogLevel logLevel, QString format, va_list vararg) {
	QByteArray qba = format.toLocal8Bit();
	log(logLevel, qba.data(),vararg);
}

void Logger::log(const char* format, ...)
{
	va_list argptr;
	va_start(argptr,format);
	log(UnknownLog, format, argptr);
	va_end(argptr);
}
void Logger::log(QString format, ...)
{
	va_list argptr;
	va_start(argptr,format);
	log(UnknownLog, format, argptr);
	va_end(argptr);
}

void Logger::error(QString format, ...)
{
	va_list argptr;
	va_start(argptr,format);
	log(CriticalLog, format, argptr);
	va_end(argptr);
}

void Logger::warning(QString format, ...)
{
	va_list argptr;
	va_start(argptr,format);
	log(WarningLog, format, argptr);
	va_end(argptr);
}

void Logger::logMatrix(float *m)
{
	return;
//	console->dumpMatrix(m);
//	return;
//	//	puts("Printing Matrix in a sexy way!\n");
//	if (m == 0)
//	{
//		log("The matrix is null");
//		return;
//	}
//	for (int i = 0; i < 4; ++i)
//	{
//		printf("|");
//		for (int j = 0; j < 4; ++j)
//		{
//			printf("%2.2f ", m[i * 4 + j]);
//		}
//		printf("|\n");
//	}
//	printf("\n");
}
